home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / AmiTCP30b2.lha / src / netlib / init_usergroup.c < prev    next >
C/C++ Source or Header  |  1994-03-29  |  4KB  |  152 lines

  1. RCS_ID_C="$Id: init_usergroup.c,v 3.1 1994/03/29 12:56:35 ppessi Exp $";
  2. /*
  3.  * autoinit.c --- SAS C auto initialization function for usergroup.library
  4.  *
  5.  * This file is part of the AmiTCP/IP User Library.
  6.  *
  7.  * Copyright © 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
  8.  *                  Helsinki University of Technology, Finland.
  9.  *                  All rights reserved.
  10.  *
  11.  * Created      : Sat Mar 20 03:31:29 1993 ppessi
  12.  * Last modified: Tue Mar 29 15:16:35 1994 ppessi
  13.  *
  14.  */
  15.  
  16. #include <exec/types.h>
  17. #include <exec/libraries.h>
  18.  
  19. #include <intuition/intuition.h>
  20.  
  21. #include <proto/exec.h>
  22. #include <proto/intuition.h>
  23. #include <dos/dosextens.h>
  24. #include <stdlib.h>
  25.  
  26. #include <libraries/usergroup.h>
  27. #include <clib/usergroup_protos.h>
  28. #include <pragmas/usergroup_pragmas.h>
  29.  
  30. struct Library *UserGroupBase = NULL;
  31.  
  32. #define USERGROUPVERSION 1    /* minimum version to use */
  33.  
  34. extern STRPTR _ProgramName;    /* SAS startup module defines this :-) */
  35. extern int errno;        /* errno variable */
  36.  
  37. /****** net.lib/autoinit_usergroup.library ************************************
  38.  
  39.     NAME
  40.         autoinit usergroup.library - SAS C Autoinitialization Functions
  41.  
  42.     SYNOPSIS
  43.         error = _STI_200_openUserGroup()
  44.  
  45.         LONG _STI_200_openUserGroup(void)
  46.  
  47.         _STD_200_closeUserGroup()
  48.  
  49.         void _STD_200_closeUserGroup(void)
  50.  
  51.     FUNCTION
  52.         These functions open and close the usergroup.library at the startup
  53.         and exit of the program, respectively.  For a program to use these
  54.         functions, it must be linked with netlib:usr.lib.
  55.  
  56.     NOTES
  57.         _STI_200_openUserGroup() also checks that the system version is at
  58.         least 37.  It puts up a requester if the usergroup.library is not
  59.         found or is too old version.
  60.  
  61.         The autoinitialization and autotermination functions are features
  62.         specific to the SAS C6.  However, these functions can be used with
  63.         other (ANSI) C compilers, too.  Example follows:
  64.  
  65.         \* at start of main() *\
  66.  
  67.         atexit(_STD_200_closeUserGroup);
  68.         if (_STI_200_openUserGroup() != 0)
  69.        exit(20);
  70.  
  71.     BUGS 
  72.         The same autoinitialization won't work for both SAS C 6.3 and SAS C
  73.         6.50 or latter.  Only way to terminate an initialization function is
  74.         by exit() call with SAS C 6.3 binary.  If an autoinitialization
  75.         function is terminated by exit() call with SAS C 6.50 binary, the
  76.         autotermination functions won't be called.  Due this braindamage
  77.         these compilers require separate net.lib libraries.
  78.  
  79.     SEE ALSO
  80.         SAS/C 6 User's Guide p. 145 for details of autoinitialization and
  81.         autotermination functions.
  82.  
  83. ****************************************************************************** */
  84.  
  85. /* SAS C 6.50 kludge */
  86. #if __VERSION__ > 6 || __REVISION__ >= 50
  87. #define exit(x) return(x)
  88. #endif
  89.  
  90. /*
  91.  * Using __stdargs prevents creation of register arguments entry point.
  92.  * If both stack args and reg. args entry points are created, this
  93.  * function is called _twice_, which is not wanted.
  94.  */
  95. LONG __stdargs
  96. _STI_200_openUserGroup(void)
  97. {
  98.   const UBYTE *errorStr = "Cannot open %s.";
  99.  
  100.   struct Process *me = (struct Process *)FindTask(NULL);
  101.   /*
  102.    * Check OS version
  103.    */
  104.   if ((*(struct Library **)4)->lib_Version < 37)
  105.     exit(20);
  106.  
  107.   /*
  108.    * Open bsdsocket.library
  109.    */
  110.   if (UserGroupBase = OpenLibrary(USERGROUPNAME, USERGROUPVERSION)) {
  111.     if (ug_SetupContextTags(_ProgramName,
  112.                 UGT_INTRMASK, SIGBREAKB_CTRL_C,
  113.                 UGT_ERRNOPTR(sizeof(errno)), &errno,
  114.                 TAG_END)
  115.     == 0)
  116.       return 0;
  117.     errorStr = "Cannot initialize context in %s.";
  118.   }
  119.  
  120.   /*
  121.    * Post requester only if approved 
  122.    */
  123.   if (me->pr_WindowPtr != (APTR) -1) {
  124.     struct Library *IntuitionBase;
  125.     if (IntuitionBase = OpenLibrary("intuition.library", 36)) {
  126.       struct EasyStruct libraryES;
  127.  
  128.       libraryES.es_StructSize = sizeof(libraryES);
  129.       libraryES.es_Flags = 0;
  130.       libraryES.es_Title = _ProgramName;
  131.       libraryES.es_TextFormat = errorStr;
  132.       libraryES.es_GadgetFormat = "Exit %s";
  133.       
  134.       EasyRequest(NULL, &libraryES, NULL, 
  135.           USERGROUPNAME, 
  136.           _ProgramName);
  137.  
  138.       CloseLibrary(IntuitionBase);
  139.     }
  140.   }
  141.  
  142.   exit(RETURN_FAIL);
  143. }
  144.  
  145. void __stdargs
  146. _STDcloseUserGroup(void)
  147. {
  148.   if (UserGroupBase != NULL) {
  149.     CloseLibrary(UserGroupBase), UserGroupBase = NULL;
  150.   }
  151. }
  152.